import LanguageMng from "../../Managers/LanguageMng";
import LanguageMngTs from "../../Managers/LanguageMngTs";
const { ccclass, property } = cc._decorator;

@ccclass
export default class transaction_details_itemTs extends cc.Component {

    @property(cc.Label)
    labelTitle1: cc.Label = null;

    @property(cc.Label)
    labelTitle2: cc.Label = null;

    @property(cc.Label)
    labelTitle3: cc.Label = null;

    @property(cc.Label)
    labelTitle4: cc.Label = null;

    @property(cc.Label)
    labelTitle5: cc.Label = null;

    public setInfo(data) {
        this.labelTitle1.string = this.timestampToTime(data.created_at);
        this.labelTitle2.string = this.LangType(data.type);
        if (data.type == 1 || data.type == 4) {
            this.labelTitle3.string = "0";
            let coin = data.deposit + data.winnings;
            this.labelTitle4.string = (coin > 0) ? "+" + coin / 100 : (coin / 100).toString();
        } else if (data.type == 2 || data.type == 3 || data.type == 5) {
            let coin = data.deposit + data.winnings;
            this.labelTitle4.string = "0";
            this.labelTitle3.string = (coin > 0) ? "+" + coin / 100 : (coin / 100).toString();
        }

        this.labelTitle5.string = ((data.winnings_balance + data.deposit_balance) / 100).toString();
    }

    /**2014-06-18 10:33:24 */
    public timestampToTime(timestamp): string {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
        var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
        return Y + M + D + "\n" + h + m + s;
    }

    public LangType(type: number): string {
        let typeName: string = "";
        switch (type) {
            case 1:
                typeName = LanguageMngTs.getSentence(350);    // "Match";  2
                break;
            case 2:
                typeName = LanguageMngTs.getSentence(351);    // "Deposit";  1
                break;
            case 3:
                typeName = LanguageMngTs.getSentence(352);    // "Withdraw";   1
                break;
            case 4:
                typeName = LanguageMngTs.getSentence(353);    //"Tournament";  2
                break;
            case 5:
                typeName = LanguageMngTs.getSentence(37);    //"Bonus";   1
                break;
            default:
                typeName = "";
                break;
        }
        return typeName;
    }
}
